package com.simonall.access.service.impl;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.simonall.access.dao.BaseDao;
import com.simonall.access.service.BaseService;

/**
 * 服务层基础类
 * 
 * @author simonall
 */
public class BaseServiceImpl<T> implements BaseService<T> {

	@Autowired
	private BaseDao<T> baseDao;

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void save(T enity) {
		baseDao.save(enity);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void update(T entity) {
		baseDao.update(entity);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void deleteById(String... id) {
		if (id != null) {
			baseDao.deleteById(id);
		}
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public T getById(Serializable id) {
		return baseDao.getById(id);
	}

}
